package cn.moningxi.service.impl;

import cn.moningxi.bean.SystemUser;
import cn.moningxi.mapper.SystemUserMapper;
import cn.moningxi.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SystemUserServiceImpl implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Override
    public SystemUser login(SystemUser systemUser) {
        SystemUser user = systemUserMapper.login(systemUser);
        return user;
    }

    @Override
    public List<SystemUser> queryAllSystemUser() {
        return systemUserMapper.queryAllSystemUser();
    }

    @Override
    public SystemUser querySystemUserById(Integer userId) {
        return systemUserMapper.querySystemUserById(userId);
    }

    @Override
    public void updateSystemUser(SystemUser systemUser) {
        systemUser.setUpdateTime(LocalDateTime.now());
        systemUserMapper.updateSystemUser(systemUser);
    }

    @Override
    public void deleteSystemUser(Integer userId) {
        systemUserMapper.deleteSystemUser(userId);
    }

    @Override
    public void addSystemUser(SystemUser systemUser) {
        systemUser.setCreateTime(LocalDateTime.now());
        systemUser.setCreateBy("system");
        systemUserMapper.addSystemUser(systemUser);

    }

    @Override
    public SystemUser queryUserByAccount(String userName) {
        return systemUserMapper.queryUserByAccount(userName);
    }
}
